﻿using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Logging.Abstractions;

using System.Diagnostics;
using System.Runtime.InteropServices;

using Volo.Abp.Data;
using Volo.Abp.DependencyInjection;
using Volo.Abp.MultiTenancy;

using Process = System.Diagnostics.Process;

namespace PLCS.Domain.Data
{
    public class PLCSDbMigrationService : ITransientDependency
    {
        private readonly IDataSeeder _dataSeeder;
        private readonly IEnumerable<IPLCSDbSchemaMigrator> _dbSchemaMigrators;

        public PLCSDbMigrationService(
            IDataSeeder dataSeeder,
            IEnumerable<IPLCSDbSchemaMigrator> dbSchemaMigrators)
        {
            _dataSeeder = dataSeeder;
            _dbSchemaMigrators = dbSchemaMigrators;
        }

        public async Task MigrateAsync()
        {
            foreach (var dbSchemaMigrator in _dbSchemaMigrators)
            {
                await dbSchemaMigrator.MigrateAsync();
            }
            await _dataSeeder.SeedAsync();
        }
    }
}